package com.admin.controller;
import com.admin.entity.Drug;
import com.admin.service.DrugService;
import com.admin.sys.base.module.extend.web.BaseController;
import com.admin.sys.base.entity.ResultInfo;
import com.admin.sys.utils.admin.StringUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * 【药品信息】页面接口
 */
@RestController
@RequestMapping("/admin/drug")
public class DrugController extends BaseController {

    @Autowired
    private DrugService drugService;

    /**
     * 【药品信息】根据条件分页查询
     * @param page
     * @param drug
     * @return
     */
    @RequestMapping("/getPage")
    public ResultInfo getPage(Page<Drug> page, Drug drug, HttpServletRequest request) {
        IPage<Drug> iPage = drugService.getPage(page, drug);
        return ResultInfo.ok("获取分页成功", iPage);
    }

    /**
     * 【药品信息】根据条件查询
     * @param drug
     * @return
     */
    @RequestMapping("/getList")
    public ResultInfo getList(Drug drug) {
        List<Drug> list = drugService.getList(drug);
        return ResultInfo.ok("获取列表成功", list);
    }

    /**
     * 【药品信息】根据对象查询
     * @param drug
     * @return
     */
    @RequestMapping("/get")
    public ResultInfo get(Drug drug) {
        Drug entity = drugService.get(drug);
        return ResultInfo.ok("获取对象成功", entity);
    }

    /**
     * 【药品信息】提交(新增或修改)
     * @param drug
     * @return
     */
    @RequestMapping("/sub")
    public ResultInfo insert(Drug drug) {
        if (StringUtils.isEmpty(drug.getId())) { // 新增
//            drug.setManufactureDate(new Date());
            drugService.insert(drug);
        } else { // 修改
            drugService.update(drug);
        }
        return ResultInfo.ok("提交成功!");
    }

    /**
     * 【药品信息】删除
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    public ResultInfo delete(String id) {
        drugService.delete(id);
        return ResultInfo.ok("删除成功!");
    }

    /**
     * 【药品信息】批量删除
     * @param ids
     * @return
     */
    @RequestMapping("/delAll")
    public ResultInfo delAll(String[] ids) {
        drugService.delAll(ids);
        return ResultInfo.ok("批量删除成功！");
    }
}

//
//import com.admin.entity.Drug;
//import com.admin.service.DrugService;
//import com.admin.sys.base.module.extend.web.BaseController;
//import com.admin.sys.base.entity.ResultInfo;
//import com.admin.sys.utils.admin.StringUtils;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//import javax.servlet.http.HttpServletRequest;
//import java.util.Date;
//import java.util.List;
//
//@RestController
//@RequestMapping("/admin/drug")
//public class DrugController extends BaseController {
//
//    @Autowired
//    private DrugService drugService;
//
//    @RequestMapping("/getPage")
//    public ResultInfo getPage(Page<Drug> page, Drug drug, HttpServletRequest request) {
//        IPage<Drug> iPage = drugService.getPage(page, drug);
//        return ResultInfo.ok("获取分页成功", iPage);
//    }
//
//    @RequestMapping("/getList")
//    public ResultInfo getList(Drug drug) {
//        List<Drug> list = drugService.getList(drug);
//        return ResultInfo.ok("获取列表成功", list);
//    }
//
//    @RequestMapping("/get")
//    public ResultInfo get(Drug drug) {
//        Drug entity = drugService.get(drug);
//        return ResultInfo.ok("获取对象成功", entity);
//    }
//
//    @RequestMapping("/sub")
//    public ResultInfo insert(Drug drug) {
//        if (StringUtils.isEmpty(drug.getDrugId())) { //新增
//            drug.setCreateDate(new Date());
//            drugService.insert(drug);
//        } else { //修改
//            drug.setUpdateDate(new Date());
//            drugService.update(drug);
//        }
//        return ResultInfo.ok("提交成功!");
//    }
//
//    @RequestMapping("/delete")
//    public ResultInfo delete(String drugId) {
//        drugService.delete(drugId);
//        return ResultInfo.ok("删除成功!");
//    }
//
//    @RequestMapping("/delAll")
//    public ResultInfo delAll(String[] drugIds) {
//        drugService.delAll(drugIds);
//        return ResultInfo.ok("批量删除成功！");
//    }
//}
//
